<!-- 权限 -->
<template>
 <div class="jurisdiction" v-if="isReloadData">
  <el-tree
  :data="data"
  show-checkbox
  empty-text=""
  node-key="id"
  default-expand-all
  ref="tree"
  :default-checked-keys="[5]"
  :props="defaultProps">
</el-tree>
<div class="but">
         <el-button type="primary" @click="getCheckedKeys">确认</el-button>
         <el-button type="info" @click="cancel">取消</el-button>
</div>
</div>
</template>

<script>
export default {
props:{
   datas:{
      type:Array
   },
   judge:{
     type:String
   }
    },
data() {
return {
   data: this.datas,
   defaultProps: {
          children: 'children',
          label: 'label'
        },
   isReloadData:true,//点击取消刷新当前页面
      };
},
//生命周期 - 创建完成（访问当前this实例）
created() {

},
//生命周期 - 挂载完成（访问DOM元素）
mounted() {

},
methods:{
    // 获取点击后的keys数组
    getCheckedKeys(){
        let checkedkey = this.$refs.tree.getCheckedKeys();
        this.$emit('checkeddata',checkedkey);//将选中数组传给父页面
    },
    //取消事件
    cancel(){
      if(this.judge == 'personage'){
          this.$router.go(-1);
      }else{
         this.reload();
      }
    },
    //刷新事件
    reload () {
      this.isReloadData = false
      this.$nextTick(() => {
        this.isReloadData = true
      })
    }
 
}
}
</script>
<style scoped>
/* @import url(); 引入css类 */
.jurisdiction .el-tree {
    position: relative;
    cursor: default;
    background: #FFF;
    color: #606266;
    width: 50%;
}
.but{
    width: 100%;
    height: 50px;
    display: flex;
    justify-content: center;
    margin-top: 3vh;
}
</style>